package com.qfedu.fmmall.controller;

import com.qfedu.fmmall.entity.ShoppingCart;
import com.qfedu.fmmall.service.ShoppingCartService;
import com.qfedu.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/shopcart")
@Api(value = "提供购物车业务相关接口",tags = "购物车管理")
public class ShopcartController {
  @Resource
    private ShoppingCartService shoppingCartService;

  @ApiOperation(value = "添加商品到购物车接口", tags = "添加商品到购物车接口")
    @PostMapping("/add")
    public ResultVO addShoppingCart(@RequestBody ShoppingCart shoppingCart){
     return  shoppingCartService.addShoppingCart(shoppingCart);
  }
  @ApiOperation(value = "查询购物车商品接口", tags = "查询购物车商品接口")
  @GetMapping("/list")
  public ResultVO selectShoppingCart(@RequestParam Integer userId){
    return  shoppingCartService.selectShoppingCart(userId);
  }

  @ApiOperation(value = "添加数量商品接口", tags = "添加购物车商品数量接口")
  @PutMapping("/update/{cid}/{cnum}")
  public ResultVO add(@PathVariable("cid") Integer cartid,@PathVariable("cnum") String cartnum){
    return  shoppingCartService.add(cartid,cartnum);
  }
  @ApiOperation(value = "查询购物车记录接口", tags = "查询购物车记录接口")
  @GetMapping("/listbycids")
  @ApiImplicitParam(name = "cids",value ="用户id",required = true,dataTypeClass = List.class)
  public ResultVO selectScart( String cids){
    return  shoppingCartService.selectScart(cids);
  }

}
